// 定义商品仓库
// 使用组合式api 定义store
import { defineStore } from 'pinia';
import { ref, reactive, computed } from 'vue';
import axios from 'axios';

export const useShopStore = defineStore('shop', () => {
    // 定义state数据
    const num = ref(0);
    // 定义action 方法
    const addNum = (n) => {
        num.value += n
    }
    // 定义state数据
    const schoolList = reactive({ schoollist: [] });
    // 定义action方法
    const initSchollListFn = () => {
        axios.get('https://api.i-lynn.cn/college').then(res => {
            // console.log(res);
            schoolList.schoollist = res.data.data.list1
        })
    }

    // 定义计算属性
    const filterSchoollist = computed(() => {
        return schoolList.schoollist.filter(item => item.school_name.includes('北京'))
    })
    // 将该仓库中的所有的数据和方法暴露出去, 这样页面才能访问到
    return {
        num,
        addNum,
        schoolList,
        initSchollListFn,
        filterSchoollist
    }



})


